using System;
using System.Text.RegularExpressions;
using System.Web;

namespace SpeakOut.Lib.Web
{
    public static class HtmlHelper
    {
        public const string BrTag = "<br />";

        public static string ToPermaLink(this string str)
        {
            string permalink = Regex.Replace(str.ToLower().Trim(), @"[\s\-]+", "-");
            return Regex.Replace(permalink, @"[^a-z0-9\-]", "");
        }

        public static string TextToSafeHtml(string str)
        {
            string safeStr = str.Replace(Environment.NewLine, BrTag);
            return safeStr;
        }

        public static string BuildPostUrl(string permalink, DateTime date)
        {
            const string postUrlPattern = @"~/{0}/{1:00}/{2:00}/{3}";
            string postUrl = string.Format(postUrlPattern, date.Year, date.Month, date.Day, permalink);
            return VirtualPathUtility.ToAbsolute(postUrl);
        }
    }
}